home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / pine3.07 / pico / bind.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-19  |  9.0 KB  |  323 lines

  1. /*
  2.  * Program:    Key binding routines
  3.  *
  4.  * Modifier:    Michael Seibel
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: mikes@cac.washington.edu
  11.  *
  12.  * Date:    19 Jan 1991
  13.  * Last Edited:    6 Jan 1992
  14.  *
  15.  * Copyright 1991 by the University of Washington
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notice appears in all copies and that both the
  20.  * above copyright notice and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  30.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  32.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35. /*    This file is for functions having to do with key bindings,
  36.     descriptions, help commands, and command line execution.
  37.  
  38.     written 11-feb-86 by Daniel Lawrence
  39.                                 */
  40.  
  41. #include    <stdio.h>
  42. #include    "estruct.h"
  43. #include    "edef.h"
  44. #include    "pico.h"
  45.  
  46.  
  47. /* 
  48.  * help - help function for pico (UW pared down version of uemacs).
  49.  *      this function will intentionally garbage with helpful 
  50.  *      tips and then wait for a ' ' to be hit to then update the 
  51.  *        screen.
  52.  */
  53.  
  54.  
  55. static char *helptext[] = {
  56.     "\tPico Help Text",
  57.     " ",
  58.     "\tPico is designed to be a simple, easy-to-use text editor with a",
  59.     "\tlayout very similar to the pine mailer.  The status line at the",
  60.     "\ttop of the display shows pico's version, the current file being",
  61.     "\tedited and whether or not there are outstanding modifications",
  62.     "\tthat have not been saved.  The third line from the bottom is used",
  63.     "\tto report informational messages and for additional command input.",
  64.     "\tThe bottom two lines list the available editing commands.",
  65.     " ",
  66.     "\tEach character typed is automatically inserted into the buffer",
  67.     "\tat the current cursor position.  Editing commands and cursor",
  68.     "\tmovement (besides arrow keys) are given to pico by typing",
  69.     "\tspecial control-key sequences.  A caret, '^', is used to denote",
  70.     "~\tthe control key, sometimes marked \"CTRL\", so the ~C~T~R~L~-~q key",
  71.     "~\tcombination is written as ~^~Q.",
  72.     " ",
  73.     "\tThe following functions are available in pico (where applicable,",
  74.     "\tcorresponding function key commands are in parentheses).",
  75.     " ",
  76.     "~\t~^~G (~F~1)   Display this help text.",
  77.     " ",
  78.     "~\t~^~F        move Forward a character.",
  79.     "~\t~^~B        move Backward a character.",
  80.     "~\t~^~P        move to the Previous line.",
  81.     "~\t~^~N        move to the Next line.",
  82.     "~\t~^~A        move to the beginning of the current line.",
  83.     "~\t~^~E        move to the End of the current line.",
  84.     "~\t~^~V (~F~8)   move forward a page of text.",
  85.     "~\t~^~Y (~F~7)   move backward a page of text.",
  86.     " ",
  87.     "~\t~^~W (~F~6)   Search for (where is) text, neglecting case.",
  88.     "~\t~^~L        Refresh the display.",
  89.     " ",
  90.     "~\t~^~D        Delete the character at the cursor position.",
  91.     "~\t~^~K (~F~9)   Delete (kill) the entire line at the cursor position.",
  92.     "\t\t  Note: consecutive deletes appended lines to a buffer ",
  93.     "\t\t        which subsequent undeletes will write at the ",
  94.     "\t\t        current cursor position.",
  95.     "~\t~^~U (~F~1~0)  Undelete last deleted line[s] at cursor position.",
  96.     "~\t~^~I        Insert a tab at the current cursor position.",
  97.     " ",
  98.     "~\t~^~J (~F~4)   Format (justify) the current paragraph.",
  99.     "\t\t  Note: paragraphs delimited by blank lines or indentation.",
  100.     "~\t~^~T (~F~1~2)  To invoke the spelling checker",
  101.     "~\t~^~C (~F~1~1)  Report current cursor position",
  102.     " ",
  103.     "~\t~^~R (~F~5)   Insert an external file at the current cursor position.",
  104.     "~\t~^~O (~F~3)   Output the current buffer to a file, saving it.",
  105.     "~\t~^~X (~F~2)   Exit pico, saving buffer.",
  106.     "    ",
  107.     "    End of Help.",
  108.     " ",
  109.     NULL
  110. };
  111.  
  112.  
  113. /*
  114.  * arraylen - return the number of bytes in an array of char
  115.  */
  116. arraylen(array)
  117. char **array;
  118. {
  119.     register int i=0;
  120.  
  121.     while(array[i++] != NULL) ;
  122.     return(i);
  123. }
  124.  
  125.  
  126. /*
  127.  * whelp - display help text for the composer and pico
  128.  */
  129. whelp(f, n)
  130. {
  131.     if(Pmaster){
  132.     (*Pmaster->helper)(Pmaster->composer_help, "Help on the Pine Composer", 1);
  133.     curwp->w_flag |= WFMODE;
  134.     }
  135.     else
  136.       pico_help(helptext);
  137.  
  138.         sgarbf = TRUE;
  139. }
  140.  
  141.  
  142.  
  143. #define    OVERLAP    2        /* displayed page overlap */
  144.  
  145. /*
  146.  * scrollw - takes beginning row and ending row to diplay an array
  147.  *           of text lines.  returns either 0 if scrolling terminated
  148.  *           normally or the value of a ctrl character typed to end it.
  149.  *
  150.  * updates - 
  151.  *     01/11/89 - added stripe call if 1st char is tilde - '~'
  152.  *
  153.  */
  154. wscrollw(begrow, endrow, textp, textlen)
  155. int    begrow, endrow;
  156. char    *textp[];
  157. int    textlen;
  158. {
  159.     register int    loffset = 0; 
  160.     register int    prevoffset = -1; 
  161.     register int    dlines;
  162.     register int    i;
  163.     register int    cont;
  164.     register int    done = 0;
  165.     register char    *buf;
  166.     int     c;
  167.      
  168.     dlines = endrow - begrow - 1;
  169.     while(!done) {
  170.         /*
  171.          * diplay a page loop ...
  172.          */
  173.     if(prevoffset != loffset){
  174.                for(i = 0; i < dlines; i++){
  175.                 movecursor(i + begrow, 0);
  176.                 peeol();
  177.                 if((loffset+i) < textlen){
  178.             buf = &(textp[loffset+i][0]);
  179.             if(*buf == '~'){
  180.             buf++;
  181.             wstripe(begrow+i, 0, buf, '~');
  182.             }
  183.             else{
  184.             pputs(buf);
  185.             }
  186.                 }
  187.             }
  188.         /*
  189.          * put up the options prompt
  190.          */
  191.             movecursor(begrow + dlines, 0);
  192.             cont = (loffset+dlines < textlen);
  193.             if(cont){                               /* continue ? */
  194.         if(loffset == 0)
  195.             wkeyhelp("000000X00V00","Exit Help,Next Pg");
  196.         else
  197.             wkeyhelp("000Y00X00V00","Prev Pg,Exit Help,Next Pg");
  198.             }
  199.             else{
  200.         if(loffset == 0)
  201.           wkeyhelp("000000X00000","Exit Help");
  202.         else
  203.           wkeyhelp("000Y00X00000","Prev Pg,Exit Help");
  204.             }
  205.     }
  206.  
  207.     (*term.t_flush)();
  208.  
  209.         c = GetKey();
  210.  
  211.     prevoffset = loffset;
  212.     switch(c){
  213.         case  (CTRL|'X') :        /* quit */
  214.          case  F2  :
  215.         done = 1;
  216.         break;
  217.         case  (CTRL|'Y') :        /* prev page */
  218.         case  F7  :            /* prev page */
  219.         if((loffset-dlines-OVERLAP) > 0){
  220.                        loffset -= (dlines-OVERLAP);
  221.         }
  222.             else{
  223.             if(loffset != 0){
  224.             prevoffset = -1;
  225.             }
  226.             else{
  227.                 (*term.t_beep)();
  228.             }
  229.             loffset = 0;
  230.             }
  231.         break;
  232.         case  (CTRL|'V') :            /* next page */
  233.          case  F8  :
  234.         if(cont){
  235.                       loffset += (dlines-OVERLAP);
  236.         }
  237.         else{
  238.            (*term.t_beep)();
  239.         }
  240.         break;
  241.         case  '\016' :        /* prev-line */
  242.         case  (CTRL|'N') :
  243.           if(cont)
  244.         loffset++;
  245.           else
  246.         (*term.t_beep)();
  247.           break;
  248.         case  '\020' :        /* prev-line */
  249.         case  (CTRL|'P') :
  250.           if(loffset > 0)
  251.         loffset--;
  252.           else
  253.         (*term.t_beep)();
  254.           break;
  255.         case  '\014' :        /* refresh */
  256.         case  (CTRL|'L') :        /* refresh */
  257.             modeline(curwp);
  258.         update();
  259.         prevoffset = -1;
  260.         break;
  261.         case  NODATA :
  262.             break;
  263.         default :
  264.         emlwrite("Unknown Command.");
  265.         (*term.t_beep)();
  266.         break;
  267.     }
  268.     }
  269.     return(TRUE);
  270. }
  271.  
  272.  
  273. /*
  274.  * normal - given a char and list of function key to command key mappings, 
  275.  *          return, depending on gmode, the right command.  The list is
  276.  *          an array of (Fkey, command-key) pairs.  sc is the index in the
  277.  *          array that means to ignore fkey vs. command key mapping
  278.  *
  279.  *          rules:  1. if c not in table (either fkey or command), let it thru
  280.  *                  2. if c matches, but in other mode, punt it
  281.  */
  282. normal(c, list, sc)
  283. int c, sc;
  284. int list[][2];
  285. {
  286.     register int i;
  287.  
  288.     for(i=0; i < 12; i++){
  289.     if(c == list[i][(FUNC&c) ? 0 : 1]){    /* in table? */
  290.         if(i == sc)                /* SPECIAL CASE! */
  291.           return(list[i][1]);
  292.  
  293.         if(list[i][1] == NODATA)        /* no mapping ! */
  294.           return(c);
  295.  
  296.         if(((FUNC&c) == FUNC) ^ ((gmode&MDFKEY) == MDFKEY))
  297.           return(BADESC);            /* keystroke not allowed! */
  298.         else
  299.           return(list[i][1]);        /* never return func keys */
  300.     }
  301.     }
  302.  
  303.     return(c);
  304. }
  305.  
  306.  
  307. /*
  308.  * rebind - replace the first function with the second
  309.  */
  310. rebindfunc(a, b)
  311. int (*a)(), (*b)();
  312. {
  313.     KEYTAB *kp;
  314.  
  315.     kp = (Pmaster) ? &keytab[0] : &pkeytab[0];
  316.  
  317.     while(kp->k_fp != NULL){        /* go thru whole list, and */
  318.     if(kp->k_fp == a)
  319.       kp->k_fp = b;            /* replace all occurances */
  320.     kp++;
  321.     }
  322. }
  323.